package com.tzxs.pay.main.first;

import android.app.Activity;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;

import com.tzxs.pay.BR;
import com.tzxs.pay.R;
import com.tzxs.pay.databinding.ActivityPendingMsgBinding;
import com.tzxs.pay.databinding.ItmeMsgNoticeBinding;
import com.tzxs.pay.main.base.BaseActivity;
import com.tzxs.pay.main.first.model.MsgNoticeBean;
import com.tzxs.pay.main.login.LoginViewModel;
import com.tzxs.pay.util.IAdapter;
import com.tzxs.pay.util.StatusBarColorSetter;
import com.tzxs.pay.util.viewmodel.Callback;

//消息中心
public class PendingMsgActivity extends BaseActivity<ActivityPendingMsgBinding> implements IAdapter.ItemNavigator<MsgNoticeBean.DataBean> {
    private LoginViewModel model;

    @Override
    protected Activity getChildActivity() {
        return this;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_pending_msg;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarColorSetter.setStatusBarColor(this, Color.parseColor("#FAFAFA"));
        model = ViewModelProviders.of(this).get(LoginViewModel.class);
        dataBinding.setViewModel(model);
        dataBinding.noticeMsg.setLayoutManager(new LinearLayoutManager(this));
        dataBinding.pendingToolbar.setNavigationOnClickListener(v -> onBackPressed());
        dataBinding.noticeMsg.setAdapter(new IAdapter<MsgNoticeBean, ItmeMsgNoticeBinding>() {
            @Override
            protected int getLayoutId(int viewType) {
                return R.layout.itme_msg_notice;
            }

            @Override
            protected void convertListener(@NonNull ItmeMsgNoticeBinding binding) {
                binding.setNavigator(PendingMsgActivity.this);
            }

            @Override
            protected int getDataBRId(int itemViewType) {
                return BR.item;
            }
        });
        //获取通知列表
        model.getNoticeList(0, 10, new Callback() {
            @Override
            public void success() {
            }
        });
    }

    @Override
    public void itemClick(MsgNoticeBean.DataBean item) {
        Intent intent = new Intent(this, PendingOrderActivity.class);
        startActivity(intent);
    }
}